Orientation Matrices

Home

Dynamics
Collision Response
Rigid Body Dynamics
Spring Tutorial
Volume Interior Finding

OpenGL
OpenGL
Orientation Matrices

Motion Capture
BVH Viewer

Planet Buster
Planet Buster

Linux
Linux and XP Bootloading

Wings3D
Wings 3D Tutorial 2
Wings 3D Tutorial

School Projects
Earlier Projects
Last Projects

Videos
EffecTV

OpenGL Stuff

Proper Camera and Object Orientation

Spring 2002

Although I implemented the spring system with a poorly made camera system, it later became necessary to have a more intuitive way of moving around and watching my work in action from different angles. A lot of trial-and-error has showed me how the MODELVIEW matrix works (It's very easy to assume one knows a bit about matrix transforms and so forth and then to start using OpenGL and find things behave very strangely when first attempted).

To summarize, there's the MODELVIEW matrix which is 4x4. It's really an array of 16 floats, oriented so indices 0-3 are the first column, 4-7 the next column, etc.:

	rightX[0]	upX[4]  outX[8]	 locationX[12]
	rightY[1] 	upY[5]  outY[9]	 locationY[13]
	rightZ[2] 	upZ[6]  outZ[10]   locationZ[14]
	0[3]	    	0[7]    0[11]	 1[15]		 
	

rightX,Y,Z is the vector that points to the right, up is up, and out is forward(other orientations are probably possible that end up looking different, but as long as the operations performed on the matrix are consistent with the layout this'll work). If you're familiar with gluLookAt(), the above matrix can be used with it like so:

	gluLookAt( 
		//eye
		viewer.matrix[12],
		viewer.matrix[13],
		viewer.matrix[14], 
	
		// center
		viewer.matrix[12]+viewer.matrix[8],
		viewer.matrix[13]+viewer.matrix[9],
		viewer.matrix[14]+viewer.matrix[10], 
	
		// up
		viewer.matrix[4],
		viewer.matrix[5],
		viewer.matrix[6]);
	

And glMultMatrixf() (while in MODELVIEW mode) can take that matrix as an argument to transform an object to the stored coordinates and orientation. So with the proper functions for rotation and movement the matrix above can be used as the basis for a camera system (with gluLookAt()) and storage for object positions and orientations. OpenGL has functions for rotations and translation that presumably would take advantage of 3d cards for carrying out the operations, but I think it may be more costly to push a matrix onto the stack, rotate it, take it out with glGetFloat() (since the stack would not be large enough to accomodate thousands of objects if the task needed it) and repeat than to just do similar things with custom functions on the cpu's time. Also, those custom functions may be made to work as needed when the OpenGL functions are more general and not always useful.




Copyright © 2002-2003 Lucas W